package starter;


import task.MessageProcessTask;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 影院服务器
 */
public class Server {

    public static ServerSocket serverSocket;
    static Server server;

    static {
        try {
            server = new Server(8888);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    public Server(int port) throws IOException {
        this.serverSocket = new ServerSocket(port);
    }

    /**
     * 服务器启动
     */
    public void start(){
        while (true){
            try {
                //等待客户端连接
                Socket client=serverSocket.accept();
                new Thread(new MessageProcessTask(client)).start();

                //信息处理

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {

        server.start();
    }
}
